package com.sugon.staticcs

import java.util

import org.apache.kafka.clients.producer.KafkaProducer


object KafkaUtil {

  // Zookeeper connection properties
  private val props = new util.HashMap[String, Object]()

  private var producer: KafkaProducer[String, String] = _

  def init(kafkaServer: String): Object = {
    props.put("bootstrap.servers", kafkaServer)
    props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
    props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")
  }

  def getProducer: KafkaProducer[String, String] = {

    if (producer == null) {
      producer = new KafkaProducer[String, String](props)
    }
    producer
  }

}
